<?php
/*
	$sql = "SELECT * FROM calendar WHERE `date` >= '$year'";
	$have = $db->queryUniqueValue($sql);
	if(!$have){
		$start = mktime(0, 0, 0, 1, 1, $year);
		$end = mktime(0, 0, 0, 1, 0, $year+1);

		for($i = $start; $i <= $end; $i = $i + DAY){
			$sql = "INSERT INTO calendar(`date`, `season`) VALUE ('".date("Y-m-d",$i)."', 'normal')";
			$db->execute($sql);
		}
	}

	foreach($_POST as $season => $value){
		if($season == "year") continue;

		foreach($value as $k => $v){
			$sql = "INSERT INTO calendar(`date`, `season`) VALUE ('".date("Y-m-d",$v)."', '$season') ON DUPLICATE KEY UPDATE `season`	= '$season'";
			$db->execute($sql);
		}
	}
	*/

	$image = new Image();

	if($file = upload("image")){

		$_POST["image"] = $file[0];

        $image->load($file[1]);
        $image->maxWidth(680);
		$image->save($file[1]);

	}

    $db->insert("calendar", $_POST);

	redirect("index.php?year=$year");
?>